package main

import (
	"fmt"
	"time"
)

func main()  {
	ch1 := make(chan struct{})
	ch2 := make(chan struct{})
	ch3 := make(chan struct{})
	finish := make(chan struct{})

	go printabc(ch1, ch2, finish, "A")
	go printabc(ch2, ch3, finish, "B")
	go printabc(ch3, ch1, finish, "C")
	ch1<-struct{}{}
	time.Sleep(10 * time.Second)
	finish<-struct{}{}
}

func printabc(pre <-chan struct{}, next chan<- struct{}, finish <-chan struct{}, str string) {
	for {
		select {
		case <-pre:
			time.Sleep(time.Second)
			fmt.Println(str)
			next<-struct{}{}
		case <-finish:
			return
		}
	}
}
